package com.andy.buyu.server.action;

import org.springframework.stereotype.Component;

import com.andy.buyu.server.game.FishGame;
import com.andy.buyu.server.game.GameUser;
import com.andy.buyu.server.socket.GmAction;
import com.andy.buyu.server.socket.MySocketSession;
import com.andy.buyu.server.socket.SendUtil;
import com.andy.buyu.server.socket.codec.DataWrap;
import com.andy.buyu.server.utils.GoConstant;

/**
 * 切换炮台逻辑
 * @author cuiwm
 *
 */
@Component(GmAction.ACTION_PREFIX+GmAction.ACTION_203)
public class Action203 implements IReqAction{

	@Override
	public void doAction(MySocketSession session, DataWrap data) {
		GameUser user = session.getUser();
		int battery = data.getByte();
		
		FishGame game = user.getGame();
		if(game == null) return;
		if(battery == GoConstant.BATTERY_TYPE_2) return;
		
		if(battery <= GoConstant.BATTERY_TYPE_1){
			// 普通切换或特殊炮到期
			user.setBattery(battery);
			SendUtil.send203(user);
		}else if(battery > GoConstant.BATTERY_TYPE_2){
			// 切换掉落的特殊炮
			if(user.exchangeBattery(battery)){
				SendUtil.send203(user);
			}
		}
	}


	
	
	
}
